import os, sys
for x in os.listdir('build'):
    if x.startswith('lib.') and '2.5' in x:
        sys.path.append(os.path.join('build', x))
from pendant import device, pendant, io_service 

# report on sync
import time
def sync_reporter(sync):
    print "sync %s at %s" % \
        ("gained" if sync else "lost", time.strftime("%I:%S")) 
sync_reporter_connection=pendant.sync.signal.connect(sync_reporter)

fft=device.ShiftFFT(80,0)
fft_sync_connection=pendant.sync.signal.connect(fft.syncChanged)
fft_sample_connection=pendant.sample.connect(fft.sampleReceived)
recorder=device.Recorder((0,), 60*60*256)
recorder_sync_connection=pendant.sync.signal.connect(recorder.syncChanged)
recorder_sample_connection=pendant.sample.connect(recorder.sampleReceived)

import wx, ui
oscilloscope=ui.Oscilloscope()
display_rate=1000.0/24 #ms
N=512
def updateDisplay():
    oscilloscope.samples=recorder.samples[-N:,0]
    oscilloscope.amplitude=fft.amplitude
    wx.CallLater(display_rate, updateDisplay)

wx.CallAfter(updateDisplay)
wx.CallAfter(io_service.run_thread)
oscilloscope.configure_traits()
